package com.xianyun.common.core.domain;
import com.xianyun.common.core.utils.AddressUtils;
import com.xianyun.common.core.utils.DeviceUtils;
import com.xianyun.common.core.utils.bean.BeanUtils;
import com.xianyun.common.core.utils.ip.IpUtils;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.servlet.http.HttpServletRequest;

/**
 * 设备详情
 * @author mac_zyj
 */
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
public class DeviceInfo {
    /**设备类型*/
    private String deviceType;
    /**操作系统*/
    private String osName;
    /**浏览器名称*/
    private String browName;
    /**版本*/
    private String version;
    /**主要版本*/
    private String majorVersion;
    /**最低版本*/
    private String minorVersion;
    /**引擎*/
    private String renderingEngine;
    /**Ip*/
    private String ip;
    /**登录地址*/
    private String realAddress;


    public DeviceInfo(HttpServletRequest request) {
        String userAgent=request.getHeader("User-Agent");
        BeanUtils.copyProperties(DeviceUtils.getDevice(userAgent),this,DeviceInfo.class);
        this.ip=IpUtils.getClientIpAddr(request);
        this.realAddress= AddressUtils.getRealAddressByIp(ip);
    }

}
